package com.learning.mapper;

import com.learning.entity.ExamPaperQuestion;
import com.learning.vo.ExamPaperQuestionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * 试卷题目关系表 Mapper 接口
 *
 * @author mhdtkc
 * @since 2024-5-29
 *
 */
@Mapper
public interface ExamPaperQuestionMapper {

    /**
     * 往试卷题目关系表插入一条数据
     */
    void insert(ExamPaperQuestion examPaperQuestion);


    /**
     * 根据试卷id查询全部试卷题目
     * @param examPaperId
     * @return
     */
    @Select("select id, exam_paper_id, question_id, question_score from exam_paper_question where exam_paper_id = #{examPaperId}")
    List<ExamPaperQuestion> selectByExamPaperId(Long examPaperId);


    /**
     * 根据试卷id和题目id查询
     * @param examPaperId
     * @param questionId
     * @return
     */
    @Select("select id, exam_paper_id, question_id, question_score from exam_paper_question where exam_paper_id = #{examPaperId} and question_id = #{questionId}")
    ExamPaperQuestion queryByExamPaperIdAndQuestionId(Long examPaperId, Long questionId);


    /**
     * 根据试卷id删除试卷中的题目
     * @param examPaperId
     */
    @Delete("delete from exam_paper_question where exam_paper_id = #{examPaperId}")
    void deleteByExamPaperId(Long examPaperId);


    /**
     * 根据题目id和试卷id删除
     * @param examPaperId
     * @param questionId
     */
    @Delete("delete from exam_paper_question where exam_paper_id = #{examPaperId} and question_id = #{questionId}")
    void deleteByExamPaperIdAndQuestionId(Long examPaperId, Long questionId);


    /**
     * 试卷题目关系表 题目表 知识点表 三表连接查询
     * @param examPaperId
     * @param questionId
     * @return
     */
    ExamPaperQuestionVO selectByExamPaperIdAndQuestionId(Long examPaperId, Long questionId);
}
